#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"

int main(int argc,char* argv[])
{
    if(argc < 3)
    {
        std::cout<<"argv[1]是原始文件路径"<<std::endl;
        std::cout<<"argv[2]是解压缩文件路径"<<std::endl;
        return -1;
    }
    std::string infilename = argv[1];
    std::string oufilename = argv[2];

    std::ifstream ifs;
    ifs.open(infilename,std::ios::binary);  //打开原始文件
    ifs.seekg(0,ifs.end);  //将光标移到末尾
    int sz = ifs.tellg(); //获取原始文件的大小
    ifs.seekg(0,ifs.beg);
    std::string body;
    body.resize(sz);
    ifs.read(&body[0],sz); //获取原始文件的数据
    
    std::string unpacked = bundle::unpack(body); //对原始文件的数据解压缩

    std::ofstream ofs;
    ofs.open(oufilename,std::ios::binary);
    ofs.write(&unpacked[0],unpacked.size()); //将解压缩文件的数据写入文件包中

    ifs.close();
    ofs.close();
    return 0;
}